%% reference point
  %% Ѱ�Ҹ��������е���Сֵ
  function [r,f]=reference_point(sorted_based_on_front)  
y=sorted_based_on_front;
  
%    [row,col] = find(sorted_based_on_front(:,n_1)==i); % �ؼ���䣬ʹ��find()����
%     y=sorted_based_on_front(row,:);
[m_1 n_1]=size(sorted_based_on_front);
    y_obj=y(:,n_1-2:n_1-1);   %%��Ŀ�������
    y_min=min(y_obj);   %%�����зֱ��Ӧ����Сֵ
    y_trans=[y(:,1:(n_1-3)) y(:,n_1-2)-y_min(1) y(:,n_1-1)-y_min(2) y(:,n_1)];
    [x_max y_max_rows1]=max(y(:,n_1-2));  %%���һ��Ŀ������ֵ����    
    [y_max y_max_rows2]=max(y(:,n_1-1));%%��ڶ���Ŀ������ֵ����
%     Y2=y(y_max_rows1,n_1-1);
%     X2=y(y_max_rows2,n_1-2);
%     
%     Y0=Y2-x_max*(y_max-Y2)/(X2-x_max);
%     X0=X2-y_max*(X2-x_max)/(y_max-Y2);   %%a1=Y0,a2=X0  �ص� intercept point
%     y_norm(:,1)=y_trans(:,n_1-2)/(Y0);   %%y���Ӧ��ֵ
%      y_norm(:,2)=y_trans(:,n_1-1)/(X0);   %%x���Ӧ��ֵ
    y_norm(:,1)=y_trans(:,n_1-2)/(x_max-y_min(1));   %%y���Ӧ��ֵ ���ַ�������0ֵ
    y_norm(:,2)=y_trans(:,n_1-1)/(y_max-y_min(2));  
    
     %% ��㵽�ο��ߵľ���
   for i=1:size(y_norm,1)
     x1=y_norm(i,1);
     y1=y_norm(i,2);
     z1(i,1)=abs(x1)/sqrt(1); %%x=0  
     z1(i,2)=abs(4*x1-y1)/sqrt(4*4+1);%%���еĵ㵽��һ���ο��ߵľ��� y=4x
     z1(i,3)=abs(1.5*x1-y1)/sqrt(1.5^2+1);  %%���еĵ㵽�ڶ����ο��ߵľ���y=3/2x
     z1(i,4)=abs(2/3*x1-y1)/sqrt((2/3)^2+1);%%���еĵ㵽�������ο��ߵľ��� y=2/3x
     z1(i,5)=abs(1/4*x1-y1)/sqrt(0.25*0.25+1);%%���еĵ㵽�������ο��ߵľ���y=1/4x
     z1(i,6)=abs(y1)/sqrt(1);  %%y=0
   end
   [z1_min,z1_loc]=min(z1,[],2);
   
   r(1,:)=sum(z1_loc==1);     %%ͳ�Ƹ�Ԫ�س��ֵ�����
   r(2,:)=sum(z1_loc==2);
   r(3,:)=sum(z1_loc==3);
   r(4,:)=sum(z1_loc==4);
   r(5,:)=sum(z1_loc==5);
   r(6,:)=sum(z1_loc==6);     
     f=[sorted_based_on_front z1_loc];
   end
 